home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / u_man / cat3 / Tcl / switch.z / switch
Encoding:
Text File  |  1998-10-30  |  5.8 KB  |  133 lines

  1.  
  2.  
  3.  
  4. sssswwwwiiiittttcccchhhh((((3333TTTTccccllll))))                                                      sssswwwwiiiittttcccchhhh((((3333TTTTccccllll))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      switch - Evaluate one of several scripts, depending on a given value
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      sssswwwwiiiittttcccchhhh ?_o_p_t_i_o_n_s? _s_t_r_i_n_g _p_a_t_t_e_r_n _b_o_d_y ?_p_a_t_t_e_r_n _b_o_d_y ...?
  13.      sssswwwwiiiittttcccchhhh ?_o_p_t_i_o_n_s? _s_t_r_i_n_g {_p_a_t_t_e_r_n _b_o_d_y ?_p_a_t_t_e_r_n _b_o_d_y ...?}
  14.  
  15.  
  16. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  17.      The sssswwwwiiiittttcccchhhh command matches its _s_t_r_i_n_g argument against each of the
  18.      _p_a_t_t_e_r_n arguments in order.  As soon as it finds a _p_a_t_t_e_r_n that matches
  19.      _s_t_r_i_n_g it evaluates the following _b_o_d_y argument by passing it recursively
  20.      to the Tcl interpreter and returns the result of that evaluation.  If the
  21.      last _p_a_t_t_e_r_n argument is ddddeeeeffffaaaauuuulllltttt then it matches anything.  If no _p_a_t_t_e_r_n
  22.      argument matches _s_t_r_i_n_g and no default is given, then the sssswwwwiiiittttcccchhhh command
  23.      returns an empty string.
  24.  
  25.      If the initial arguments to sssswwwwiiiittttcccchhhh start with ---- then they are treated as
  26.      options.  The following options are currently supported:
  27.  
  28.      ----eeeexxxxaaaacccctttt    Use exact matching when comparing _s_t_r_i_n_g to a pattern.  This is
  29.                the default.
  30.  
  31.      ----gggglllloooobbbb     When matching _s_t_r_i_n_g to the patterns, use glob-style matching
  32.                (i.e. the same as implemented by the ssssttttrrrriiiinnnngggg mmmmaaaattttcccchhhh command).
  33.  
  34.      ----rrrreeeeggggeeeexxxxpppp   When matching _s_t_r_i_n_g to the patterns, use regular expression
  35.                matching (i.e. the same as implemented by the rrrreeeeggggeeeexxxxpppp command).
  36.  
  37.      --------        Marks the end of options.  The argument following this one will
  38.                be treated as _s_t_r_i_n_g even if it starts with a ----.
  39.  
  40.      Two syntaxes are provided for the _p_a_t_t_e_r_n and _b_o_d_y arguments.  The first
  41.      uses a separate argument for each of the patterns and commands; this form
  42.      is convenient if substitutions are desired on some of the patterns or
  43.      commands.  The second form places all of the patterns and commands
  44.      together into a single argument; the argument must have proper list
  45.      structure, with the elements of the list being the patterns and commands.
  46.      The second form makes it easy to construct multi-line switch commands,
  47.      since the braces around the whole list make it unnecessary to include a
  48.      backslash at the end of each line.  Since the _p_a_t_t_e_r_n arguments are in
  49.      braces in the second form, no command or variable substitutions are
  50.      performed on them;  this makes the behavior of the second form different
  51.      than the first form in some cases.
  52.  
  53.      If a _b_o_d_y is specified as ``----'' it means that the _b_o_d_y for the next
  54.      pattern should also be used as the body for this pattern (if the next
  55.      pattern also has a body of ``----'' then the body after that is used, and so
  56.      on).  This feature makes it possible to share a single _b_o_d_y among several
  57.      patterns.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. sssswwwwiiiittttcccchhhh((((3333TTTTccccllll))))                                                      sssswwwwiiiittttcccchhhh((((3333TTTTccccllll))))
  71.  
  72.  
  73.  
  74.      Below are some examples of sssswwwwiiiittttcccchhhh commands:
  75.  
  76.           sssswwwwiiiittttcccchhhh aaaabbbbcccc aaaa ---- bbbb {{{{ffffoooorrrrmmmmaaaatttt 1111}}}} aaaabbbbcccc {{{{ffffoooorrrrmmmmaaaatttt 2222}}}} ddddeeeeffffaaaauuuulllltttt {{{{ffffoooorrrrmmmmaaaatttt 3333}}}}
  77.  
  78.      will return 2222,
  79.  
  80.           sssswwwwiiiittttcccchhhh ----rrrreeeeggggeeeexxxxpppp aaaaaaaaaaaabbbb {{{{
  81.             ^^^^aaaa....****bbbb$$$$ ----
  82.             bbbb {{{{ffffoooorrrrmmmmaaaatttt 1111}}}}
  83.             aaaa**** {{{{ffffoooorrrrmmmmaaaatttt 2222}}}}
  84.             ddddeeeeffffaaaauuuulllltttt {{{{ffffoooorrrrmmmmaaaatttt 3333}}}}
  85.           }}}}
  86.  
  87.      will return 1111, and
  88.  
  89.           sssswwwwiiiittttcccchhhh xxxxyyyyzzzz {{{{
  90.             aaaa
  91.               ----
  92.             bbbb
  93.               {{{{ffffoooorrrrmmmmaaaatttt 1111}}}}
  94.             aaaa****
  95.               {{{{ffffoooorrrrmmmmaaaatttt 2222}}}}
  96.             ddddeeeeffffaaaauuuulllltttt
  97.               {{{{ffffoooorrrrmmmmaaaatttt 3333}}}}
  98.           }}}}
  99.  
  100.      will return 3333.
  101.  
  102.  
  103. KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  104.      switch, match, regular expression
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.